--
-- Author: shunguo.chen
-- Date: 2018-01-09 16:21:20
--
-- CosplayBookView CosplayRole 详情展示

local AvatarFactory = app:getClass("AvatarFactory")

local CosplaySkillRender = import(".renders.CosplaySkillRender")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.CosplayBookScene

function ClassRef:init()
	self._ui.Button_close:addClickEventListener(function()
			executeFunc(self._onCloseView, self)
		end)

	self._tltText = self._ui["Panel/Panel_left/tlt"]
	self._descText = self._ui["Panel/Panel_left/Text"]
	self._roleCon = self._ui["Panel/Panel_left/Panel_player"]

	-- skills
	self._list = self._ui["Panel/Panel_right/ListView"]
	self._list.createRender = function (list, idx)
		local items = list:getItems()
    	local render = items[idx]
    	if nil == render then
			render = CosplaySkillRender.create()
			list:pushBackCustomItem(render)
		end
		render:setVisible(true)
		return render
	end
end

-- data = CosplayRole
function ClassRef:refresh(data)
	local avatarParams = data:getAvatarParams()
	self._tltText:setString(avatarParams.name)
	self._descText:setString(data:getDesc())

	-- avatar
	self._roleCon:removeAllChildren()
	local hero = AvatarFactory.createHero(avatarParams)
	hero:setPositionX(self._roleCon:getContentSize().width/2)
	self._roleCon:addChild(hero)
	hero:play("mapidle")

	-- skill
	local skills = data:getSkills()
	for i,skill in ipairs(skills) do
		local render = self._list:createRender(i)
		render:setRole(data)
		render:setData(skill)
	end
end

return ClassRef